package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysNovelBookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysNovelChapterMapper;
import com.ruoyi.system.domain.SysNovelChapter;
import com.ruoyi.system.service.ISysNovelChapterService;

/**
 * 章节列表Service业务层处理
 * 
 * @author ZouYangMing
 * @date 2022-11-09
 */
@Service
public class SysNovelChapterServiceImpl implements ISysNovelChapterService 
{
    @Autowired
    private SysNovelChapterMapper sysNovelChapterMapper;

    @Autowired
    private SysNovelBookMapper sysNovelBookMapper;

    /**
     * 查询章节
     * 
     * @param id 章节主键
     * @return 章节
     */
    @Override
    public SysNovelChapter selectSysNovelChapterById(Long id)
    {
        return sysNovelChapterMapper.selectSysNovelChapterById(id);
    }

    /**
     * 查询章节列表
     * 
     * @param sysNovelChapter 章节
     * @return 章节列表
     */
    @Override
    public List<SysNovelChapter> selectSysNovelChapterList(SysNovelChapter sysNovelChapter)
    {
        List<SysNovelChapter> list = sysNovelChapterMapper.selectSysNovelChapterList(sysNovelChapter);
        for (SysNovelChapter novelChapter : list) {
            if (novelChapter.getBookId() != null) {
                novelChapter.setBookName(sysNovelBookMapper.selectSysNovelBookById(novelChapter.getBookId()).getBookName());
            }
        }
        return list;
    }

    /**
     * 新增章节列表
     * 
     * @param sysNovelChapter 章节列表
     * @return 结果
     */
    @Override
    public int insertSysNovelChapter(SysNovelChapter sysNovelChapter)
    {
        sysNovelChapter.setCreateBy(SecurityUtils.getUsername());
        sysNovelChapter.setCreateTime(DateUtils.getNowDate());
        return sysNovelChapterMapper.insertSysNovelChapter(sysNovelChapter);
    }

    /**
     * 修改章节列表
     * 
     * @param sysNovelChapter 章节列表
     * @return 结果
     */
    @Override
    public int updateSysNovelChapter(SysNovelChapter sysNovelChapter)
    {
        sysNovelChapter.setUpdateBy(SecurityUtils.getUsername());
        sysNovelChapter.setUpdateTime(DateUtils.getNowDate());
        return sysNovelChapterMapper.updateSysNovelChapter(sysNovelChapter);
    }

    /**
     * 批量删除章节列表
     * 
     * @param ids 需要删除的章节列表主键
     * @return 结果
     */
    @Override
    public int deleteSysNovelChapterByIds(Long[] ids)
    {
        return sysNovelChapterMapper.deleteSysNovelChapterByIds(ids);
    }

    /**
     * 删除章节列表信息
     * 
     * @param id 章节列表主键
     * @return 结果
     */
    @Override
    public int deleteSysNovelChapterById(Long id)
    {
        return sysNovelChapterMapper.deleteSysNovelChapterById(id);
    }
}
